# Paper: Is it still the economy? Economic voting in polarized politics
# Individual-level simulation
# Replication: Table S13 (Supplementary Material)
remove(list = ls())

library(conflicted)
library(tidyverse)
library(dplyr)
conflict_prefer("filter","dplyr")
library(ggplot2)
library(here) # When we have an R-project, it reads files without setting an directory
conflict_prefer("here", "here")
library(sandwich)
library(fixest)

load(here("Final_Paper", "R&R", "LongSeries_Data.RData"))
glimpse(final_data)
table(final_data$year)

final_data <- final_data %>% 
  mutate(inc_share_delta = inc_share-laginc_share)

# OLS
summary(ols_model2 <- lm(inc_share_delta ~ wages_perworker_real_delta*elitepolar_house + 
                           state + rep_pres + inc_cand, 
                         data = final_data))

# Clustered Standard Errors
coeffs_cl <- coeftest(ols_model2, vcov = vcovCL, cluster = ~ fips_numeric)
coeffs_cl

# County Fixed Effects
summary(fe_model <- feols(inc_share_delta ~ wages_perworker_real_delta*elitepolar_house + 
                            state + rep_pres + inc_cand | fips_numeric, 
                          data = final_data))



